﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.Xna.Framework;

namespace VikingArcade_v2._0
{
    public class Router
    {
        private static GameState gameState;

        public static GameState GameState
        {
            get
            {
                return gameState;
            }
            set
            {
                if(gameState != value)
                {
                    foreach (IGameStateObserver gameStateObserver in gameStateObservers)
                    {
                        if(gameStateObserver!= null)
                        {
                            gameStateObserver.Notify(value);
                        }
                    }
                }
                gameState = value;

            }
        }

        private static List<IGameStateObserver> gameStateObservers = new List<IGameStateObserver>();

        public DisplayController DisplayController { get;set; }

        public UserInterfaceController UserInterfaceController { get; set; }

        public GameplayController GameplayController { get; set; }

        public AnimationController AnimationController { get; set; }

        public MusicController MusicController { get; set; }

        public Router(GraphicsDeviceManager graphicsDeviceManager)
        {
            GameState = GameState.Initializing;

            DisplayController = new DisplayController(graphicsDeviceManager);

            AnimationController = new AnimationController();

            UserInterfaceController = new UserInterfaceController();
            gameStateObservers.Add(UserInterfaceController);

            MusicController = new MusicController();
        }

        public void Update(GameTime gameTime)
        {
            List<IAnimator> animators = new List<IAnimator>();

            //TODO: Get all Animators

            AnimationController.Animate(animators, gameTime);

            MusicController.Update();

            UserInterfaceController.UpdateInput();

            switch (GameState)
            {
                case GameState.Initializing:
                    GameState = GameState.Menu;
                    break;
            }
        }

        public void Draw()
        {
            List<IDrawer> drawers = new List<IDrawer>();

            //TODO: Get all Drawers
            drawers.Add(UserInterfaceController.UserInterface.GetDrawer());

            DisplayController.Display.Draw(drawers);
        }
    }
}
